package com.yj.consumer.controller;

import com.yj.pojo.Payment;
import com.yj.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    //调用支付服务端的ip+端口号，微服务采用服务名进行访问
    public static final String PAYMENT_URL = "http://microservice-provider";

    @Autowired
    private RestTemplate restTemplate;

    //创建支付订单的接口
    @GetMapping("/payment/create")
    public Result<Payment> create(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, Result.class);
    }

    //获取id获取支付订单
    @GetMapping("/payment/get/{id}")
    public Result<Payment> getPayment(@PathVariable("id") Long id) {
//        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, Result.class);
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/{id}", Result.class, id);
    }
}
